package dtu.k12tpm.pbs.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.EditText;

public class LinedEditText extends EditText {
	private Paint mPaint; 
    private Paint mVert;

    // we need this constructor for LayoutInflater 
    public LinedEditText(Context context, AttributeSet attrs) { 
            super(context, attrs); 
            setBackgroundColor(Color.YELLOW);
            setTypeface(Typeface.SERIF, Typeface.ITALIC);
            setTextSize(15.0f);
            mPaint = new Paint(); 
            mPaint.setStyle(Paint.Style.STROKE); 
            mPaint.setARGB(100, 0, 0, 255); 
            mVert = new Paint(); 
            mVert.setStyle(Paint.Style.STROKE); 
            mVert.setARGB(100, 255, 0, 0); 
            setPadding(20, 0, 0, 0); 
            
    } 

    @Override 
    protected void onDraw(Canvas canvas) { 
            int count = getLineCount(); 

            Paint paint = mPaint; 

            int height = getHeight(); 
            int line_height = getLineHeight()+4; 
            int page_size = height / line_height; 
             
            if (count < page_size) { 
                    count = page_size; 
            } 
            for (int i=1; i< count+2; i++) { 
                    int posY = 0;  
                             posY = i*line_height; 
                     canvas.drawLine(getLeft(), posY -1, getRight(), posY -1, paint); 
            } 
                     
            canvas.drawLine(10, 0, 10, count*line_height, mVert); 
            canvas.drawLine(15, 0, 15, count*line_height, mVert); 
             
            super.onDraw(canvas); 
    } 
}
